﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using ZhouYu.NewWorld.BLL.IService;
using ZhouYu.NewWorld.Model;
using ZhouYu.NewWorld.ViewModel;
using ZhouYu.NewWorld.Web.Models;

namespace ZhouYu.NewWorld.Web.Controllers
{
    public class HomeController : Controller
    {

        //注入
        private ICateraccommodService _cateraccommodService;
        private IWebcolumnService _webcolumnService;
        private IUserService _userService;
        private IWebsiteService _websiteService;
        private IScenicpicService _scenicpicService;
        private IScenicspotService _scenicspotService;
        private IGoodsService _goodsService;
        private IPictureService _picture;
        private IOrderInfoService _orderInfoService;
        private ITourPicService _tourPicService;
        private ITourService _tourService;
        private ICountryLocationService _countryLocationService;
        private IProvinceLocationService _provinceLocationService;
        private ICityLocationService _cityLocationService;
        private ITouristrouteService _touristrouteService;
        private IHotelService _hotelService;
        private IDeliveryAddressService _deliveryAddressService;
        private IVoucherService _voucherService;
        private ITravelVoService _travelVoService;
        private IBackcolumnService _backcolumnService;
        private ICategoryService _categoryService;
        private ICashnumberService _cashnumberService;
        public HomeController(IUserService userService, IWebsiteService websiteService, IScenicpicService scenicpicService, IScenicspotService scenicspotService, IGoodsService goodsService, IPictureService picture, IOrderInfoService orderInfoService, ITourPicService tourPicService,ITourService tourService, ICountryLocationService countryLocationService, IProvinceLocationService provinceLocationService, ICityLocationService cityLocationService, ITouristrouteService touristrouteService, IHotelService hotelService, IDeliveryAddressService deliveryAddressService, IVoucherService voucherService, ITravelVoService travelVoService,ICategoryService categoryService, ICashnumberService cashnumberService, IBackcolumnService backcolumnService, ICateraccommodService cateraccommodService, IWebcolumnService webcolumnService)
        {
             _cateraccommodService = cateraccommodService;
            _webcolumnService = webcolumnService;
            _userService = userService;
            _websiteService = websiteService;
            _scenicpicService = scenicpicService;
            _scenicspotService = scenicspotService;
            _goodsService = goodsService;
            _picture = picture;
            _voucherService = voucherService;
            _orderInfoService = orderInfoService;
            _tourPicService = tourPicService;
            _tourService = tourService;
            _countryLocationService = countryLocationService;
            _provinceLocationService = provinceLocationService;
            _cityLocationService = cityLocationService;
            _touristrouteService = touristrouteService;
            _hotelService = hotelService;
            _deliveryAddressService = deliveryAddressService;
            _travelVoService = travelVoService;
            _categoryService = categoryService;
            _cashnumberService = cashnumberService;
            _backcolumnService = backcolumnService;
        }

        /// <summary>
        /// 主页
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Index()
        { 
            List<Backcolumn> backcolumns = _backcolumnService.QueryList(a => true);
            ViewBag.List = backcolumns;
            return View();
        }

        /// <summary>
        /// 现金账号
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult CashNumber()
        {
            //获取用户表
            List<UserInfo> userInfos = _userService.QueryList(a => true);
            ViewBag.userInfos = userInfos;
            return View();
        }


        /// <summary>
        /// 旅游图片管理页面
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult ScenicPic()
        {
            return View();
        }

        public ActionResult home()
        {
            return View();
        }

        /// <summary>
        /// 添加旅游图片页面
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Add_ScenicPic()
        {
            //获取旅游景点集合
            Expression<Func<Scenicspot, bool>> expression = a => true;
            ViewBag.list = _scenicspotService.QueryList(expression);
            return View();
        }

        /// <summary>
        /// 编辑旅游图片页面
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Edit_ScenicPic(int id)
        {
            //获取对应图片对象
            Expression<Func<Scenicpic, bool>> expression1 = a => a.Pic_Id==id;
            ViewBag.pic = _scenicpicService.Query(expression1);

            //获取旅游景点集合
            Expression<Func<Scenicspot, bool>> expression = a => true;
            ViewBag.list = _scenicspotService.QueryList(expression);
            return View();
        }


        /// <summary>
        /// 旅游团购图片管理
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult TourPic()
        {
            return View();
        }

        /// <summary>
        /// 添加团购图片管理
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Add_TourPic()
        {
            //获取商品集合
            Expression<Func<Tour, bool>> expression = a => true;
            ViewBag.list = _tourService.QueryList(expression);
            return View();
        }


        /// <summary>
        /// 编辑团购图片管理
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Edit_TourPic(int id)
        {
            //获取对应团购图片对象
            Expression<Func<TourPicture, bool>> expression1 = a => a.TourPic_Id == id;
            ViewBag.pic = _tourPicService.Query(expression1);

            //获取旅游团购集合
            Expression<Func<Tour, bool>> expression = a => true;
            ViewBag.list = _tourService.QueryList(expression);
            return View();
        }


        /// <summary>
        /// 商品图片管理页面
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Picture()
        {
            return View();
        }

        /// <summary>
        /// 添加商品图片页面
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Add_Picture()
        {
            
            //获取商品集合
            Expression<Func<Goods, bool>> expression = a => true;
            ViewBag.list = _goodsService.QueryList(expression);
            return View();
        }
        /// <summary>
        /// 编辑商品图片页面
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Edit_Picture(int id)
        { 
            //获取对应图片对象
            Expression<Func<Picture, bool>> expression1 = a => a.PictureId == id;
            ViewBag.pic = _picture.Query(expression1);



            //获取商品集合
            Expression<Func<Goods, bool>> expression = a => true;
            ViewBag.list = _goodsService.QueryList(expression);
            return View();
        }


        /// <summary>
        /// 网站底部导航管理
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult WebColumn()
        {
            int page = 0, limit = 0;
            int count;
            Expression<Func<Webcolumn, bool>> whereLambda = a => true;
            Expression<Func<Webcolumn, int>> orderbyLambda = a => a.WebColumn_Id;
            List<Webcolumn> result = _webcolumnService.QueryPageList(page, limit, whereLambda, orderbyLambda, out count);
            //获取总条数
            ViewBag.count = count;
            return View();
        }

        /// <summary>
        /// 后台导航管理
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult BackColumn()
        {
            //获取父级组
            List<Backcolumn> backcolumn = _backcolumnService.QueryList(a => a.BackColumn_ParentId == 0);
            ViewBag.categories = backcolumn;
            return View();
        }

        /// <summary>
        /// 团购管理页面
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Tour()
        {
            return View();
        }


        /// <summary>
        /// 团购管理页面
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Edit_Tour(int id)
        {
            
            //获取旅游团购集合
            Expression<Func<Tour, bool>> expression = a => a.TourId==id;
            Tour tour = _tourService.Query(expression);
            ViewBag.tour = tour;

            //出发地--获取团购对应城市对象
            Expression<Func<Citylocation, bool>> expression3 = a => a.City==tour.StartPlace;
            Citylocation citylocation = _cityLocationService.Query(expression3);
            //出发地--根据父级id查询对应省份下的城市集合
            Expression<Func<Citylocation, bool>> expression4 = a => a.ParentId == citylocation.ParentId;
            ViewBag.City = _cityLocationService.QueryList(expression4);
            //出发地--根据父级id获取对应省份对象
            Expression<Func<Provincelocation, bool>> expression2 = a => a.Id==citylocation.ParentId;
            Provincelocation provincelocation = _provinceLocationService.Query(expression2);
            //出发地--根据父级id获取对应国家下的省份集合
            Expression<Func<Provincelocation, bool>> expression5 = a => a.ParentId == provincelocation.ParentId;
            ViewBag.Province = _provinceLocationService.QueryList(expression5);


            //目的地--获取团购对应城市对象
            Expression<Func<Citylocation, bool>> expression6 = a => a.City == tour.EndPlace;
            Citylocation citylocations = _cityLocationService.Query(expression6);
            //目的地--根据父级id查询对应省份下的城市集合
            Expression<Func<Citylocation, bool>> expression7 = a => a.ParentId == citylocations.ParentId;
            ViewBag.Citys = _cityLocationService.QueryList(expression7);
            //目的地--根据父级id获取对应省份对象
            Expression<Func<Provincelocation, bool>> expression8 = a => a.Id == citylocations.ParentId;
            Provincelocation provincelocations = _provinceLocationService.Query(expression8);
            //目的地根据父级id获取对应国家下的省份集合
            Expression<Func<Provincelocation, bool>> expression9 = a => a.ParentId == provincelocations.ParentId;
            ViewBag.Provinces = _provinceLocationService.QueryList(expression5);

            //获取国家集合
            Expression<Func<Countrylocation, bool>> expression1 = a => true;
            ViewBag.Country = _countryLocationService.QueryList(expression1);
            return View();
        }



        /// <summary>
        /// 旅游线路管理页面
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        //[Authentication]
        public ActionResult TouristRoute()
        {
            //获取旅游景点集合
            Expression<Func<Scenicspot, bool>> expression = a => true;
            ViewBag.Scenicspotlist = _scenicspotService.QueryList(expression);
            //获取酒店集合
            Expression<Func<Hotel, bool>> expression1 = a => true;
            ViewBag.HotelList = _hotelService.QueryList(expression1);
            //获取城市集合
            Expression<Func<Citylocation, bool>> expression2 = a => true;
            ViewBag.CitylList = _cityLocationService.QueryList(expression2);
            return View();
        }

        /// <summary>
        /// 添加路线
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult AddTouristRoute()
        {
            return View();
        }

        /// <summary>
        /// 交通线路管理
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult RouteInfo()
        {
            return View();
        }

        /// <summary>
        /// 酒店管理
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Hotel()
        {
            int page = 0, limit = 0;
            int count;
            Expression<Func<Hotel, bool>> whereLambda = a => true;
            Expression<Func<Hotel, int>> orderbyLambda = a => a.HotelId;
            List<Hotel> result = _hotelService.QueryPageList(page, limit, whereLambda, orderbyLambda, out count);
            //获取总条数
            ViewBag.count = count;
            return View();
        }
        [Authentication]
        public ActionResult AddHotel() 
        {
            return View();
        }

        /// <summary>
        /// 餐饮住宿管理 
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult CaterAccommod()
        {
            int page = 0, limit = 0;
            int count;
            Expression<Func<Cateraccommod, bool>> whereLambda = a => true;
            Expression<Func<Cateraccommod, int>> orderbyLambda = a => a.CaterId;
            List<Cateraccommod> result = _cateraccommodService.QueryPageList(page, limit, whereLambda, orderbyLambda, out count);
            //获取总条数
            ViewBag.count = count;
            return View();
        }

        /// <summary>
        /// 网站参数管理
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Website()
        {
            int page = 0, limit = 0;
            int count;
            Expression<Func<Website, bool>> whereLambda = a => true;
            Expression<Func<Website, int>> orderbyLambda = a => a.Website_Id;
            List<Website> result = _websiteService.QueryPageList(page, limit, whereLambda, orderbyLambda, out count);
            //获取总条数
            ViewBag.count = count;
            return View();
        }

        /// <summary>
        /// 提问管理
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Questions()
        {
            return View();
        }

        /// <summary>
        /// 回复管理
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Reply()
        {
            return View();
        }

        /// <summary>
        /// 点评管理
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult UserComment()
        {
            return View();
        }

        /// <summary>
        /// 旅游景点管理
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        //[Authentication]
        public ActionResult ScenicSpot()
        {
            return View();
        }

        /// <summary>
        /// 登录页面
        /// </summary>
        /// <returns></returns>
        /// 
        public ActionResult Login()
        {
            //取出Cookie保存的信息
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies.Get("CookieName");
            if (cookie != null)
            {
                string name = cookie["AdminName"];
                string pwd = cookie["AdminPwd"];
                //不记住密码
                if (name != null && pwd == null)
                {
                    //将Cookie中的值赋给上下文session  使其在不登录时页面也能够显示
                    AdminUserContext.adminContext.Admin = new Admin()
                    {
                        AdminName = name,
                    };
                }
                //记住密码
                else if (name != null && pwd != null && DateTime.Parse(cookie["DateTime"]) != null && DateTime.Now < DateTime.Parse(cookie["DateTime"]))
                {
                    //将Cookie中的值赋给上下文session  使其在不登录时页面也能够显示
                    AdminUserContext.adminContext.Admin = new Admin()
                    {
                        AdminName = name,
                        AdminPwd = pwd
                    };
                }
            }

            return View();
        }


        /// <summary>
        /// 用户信息管理
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult UserInfo()
        {
            return View();
        }


        /// <summary>
        /// 积分管理页面
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Integral()
        {
            return View();
        }


        /// <summary>
        /// 配送地址管理页面
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult DeliveryAddress()
        {

            return View();
        }
        /// <summary>
        /// 配送地址管理添加页面
        /// </summary>
        /// <returns></returns>
        [Authentication]
        public ActionResult DeliveryAddressAdd()
        {

            return View();
        }
        /// <summary>
        /// 配送地址管理修改页面
        /// </summary>
        /// <returns></returns>
        [Authentication]
        public ActionResult DeliveryAddressUpdate(int id)
        {
            if (id > 0)
            {
                Expression<Func<DeliveryAddress, bool>> lambdaExpression = a => a.Delivery_Id == id;
                //获取功能
                ViewBag.deliveryAddress = _deliveryAddressService.Query(lambdaExpression);
            }
           
            return View();
            
        }



        //修改权限页面
        //[PermissionAttribute]
        [Authentication]
        public ActionResult UpdateCompetence(int id)
        {

            return View();
        }

        /// <summary>
        /// 订单管理
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult OrderInfo()
        {

            return View();
        }

        /// <summary>
        /// 编辑订单页面
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Edit_OrderInfo(int id)
        {
            //获取对应订单对象
            Expression<Func<OrderInfo, bool>> expression1 = a => a.Order_Id == id;
            ViewBag.order = _orderInfoService.Query(expression1);
            return View();
        }




        //系统日志页面
        //[PermissionAttribute]
        [Authentication]
        public ActionResult SystemLogs()
        {
            return View();
        }

        /// <summary>
        /// 旅游卷管理
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult TravelVo()
        {

            return View();
        }


        /// <summary>
        /// 添加旅游卷页面
        /// </summary>
        /// <returns></returns>
        [Authentication]
        public ActionResult Add_TravelVo()
        {
            //获取用户集合
            Expression<Func<UserInfo, bool>> expression = a => true;
            ViewBag.list = _userService.QueryList(expression);
            return View();
        }

        /// <summary>
        /// 编辑旅游卷页面
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Edit_TravelVo(int id)
        {
            //获取对应抵用卷对象
            Expression<Func<Travelvo, bool>> expression1 = a => a.TravelVo_Id == id;
            ViewBag.Travelvo = _travelVoService.Query(expression1);

            //获取用户集合
            Expression<Func<UserInfo, bool>> expression = a => true;
            ViewBag.user = _userService.QueryList(expression);
            return View();
        }

        /// <summary>
        /// 抵用卷页面
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Voucher()
        {

            return View();
        }

        /// <summary>
        /// 添加抵用卷页面
        /// </summary>
        /// <returns></returns>
      [Authentication]
        public ActionResult Add_Voucher()
        {
            //获取用户集合
            Expression<Func<UserInfo, bool>> expression = a => true;
            ViewBag.list = _userService.QueryList(expression);
            return View();
        }

        /// <summary>
        /// 编辑抵用卷页面
        /// </summary>
        /// <returns></returns>
        //[PermissionAttribute]
        [Authentication]
        public ActionResult Edit_Vocher(int id)
        {
            //获取对应抵用卷对象
            Expression<Func<Voucher, bool>> expression1 = a => a.Voucher_Id == id;
            ViewBag.voucher = _voucherService.Query(expression1);

            //获取用户集合
            Expression<Func<UserInfo, bool>> expression = a => true;
            ViewBag.user = _userService.QueryList(expression);
            return View();
        }

        [Authentication]
        public ActionResult AddAdmin()
        {
            return View();
        }

        /// <summary>
        /// 地区特产分类
        /// </summary>
        /// <returns></returns>
         [Authentication]
        public ActionResult Category() 
        {
            //获取父级组
            List<Category> categories = _categoryService.QueryList(a => a.ParentId == 0);
            ViewBag.categories = categories;

            int page = 0, limit = 0;
            int count;
            Expression<Func<Category, bool>> whereLambda = a => true;
            Expression<Func<Category, int>> orderbyLambda = a => a.CategoryId;
            List<Category> result = _categoryService.QueryPageList(page, limit, whereLambda, orderbyLambda, out count);
            //获取总条数
            ViewBag.count = count;
            return View();
        }

        /// <summary>
        /// 商品分类
        /// </summary>
        /// <returns></returns>
        [Authentication]
        public ActionResult Goods() 
        {
            ViewBag.brands = _goodsService.GetBrand().data;
            ViewBag.suppliers = _goodsService.GetSupplier().data;
            return View();
        }
    }
}